<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sửa đổi tình trạng đơn hàng</title>
</head>

<body>

<?PHP
	require ('models/m_phieuxuat.php');
	require ('models/sharefunction.php');
	
	   	 $post=getbyid_hoadon($_GET['id']);
		 $nd= getbyid_nguoidung($post["ID_Nguoi_dung"]);
 		 $tthd=getbyall_tthd();	
		 $gettthd = getbyid_ttdh($post['ID_Tinh_trang_hoa_don']);
		if (isset($_POST['update']) )
			{ 
			if($_POST['ID_Tinh_trang_hoa_don']==3){
				 $ctx=getbyid_ctx($_GET['id']);
				 foreach($ctx as $ctx){
					 $soluongban=$ctx['So_luong'];
					 $sach=getbyid_sach($ctx['ID_Sach']);
					 $tonkho = $sach['So_luong'];
					 $conlai=$tonkho-$soluongban;
					  update_soluong($conlai,$ctx['ID_Sach']);
					  
					 }
				include('../phpmailer/guidonhang1.php');
				}
			
			
				update_tthd($_POST);
		        header('Location: doitinhtrang.php?id='.$_GET['id']);

			
			}

	require ('v_doitinhtrang.php'); 
	
?>
</body>
</html>